/*******************************************************************************
 * This file is part of blueprint4j www.blueprint4j.org.
 * 
 *     blueprint4j is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Lesser General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     blueprint4j is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Lesser General Public License for more details.
 * 
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with blueprint4j. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package blueprint4j.db;

import java.util.*;
import java.text.*;

public class DateRange {

	private Date from_date = null;
	private Integer days = null;
	private SimpleDateFormat simple_date_format = new SimpleDateFormat("yyyyMMdd");
	
	public DateRange(Date p_from_date,Integer p_days) {
		// strip time from date field
		try {
			from_date = simple_date_format.parse(simple_date_format.format(p_from_date));
		} catch (ParseException parse_exception) {
			parse_exception.printStackTrace();
		}
		days = p_days;
	}	
	
	public Date getFromDate() {
		return from_date;
	}
	
	public Integer getDays() {
		return days;
	}
	
	public boolean isDayValid(Date p_date) {
		if (days == null) {
			return from_date.getTime() < p_date.getTime();
		}
		return (p_date.getTime() >= from_date.getTime() && p_date.getTime() <= (from_date.getTime() + days.intValue() * 1000 * 60 * 24));  
	}
}
